﻿<%@ codepage=65001%>
<!-- #include file="conn.asp" -->
<%
Session.CodePage=65001
Response.Charset="utf-8"

sType = request("sType")

if (IsEmpty(request("id")) or request("id")="" ) then
	id=0
else
	id=cint(trim(request("id")))
end if

username=request("username")
password=request("password")
p=request("useTypeUpdate")
wdId = request("wdIdSecond")

if sType = "add" then
	'on error resume next
	set rs= server.createobject("adodb.recordset")
	if id>0 then    'update
		sql="update [userInfo] set [username]='"&username&"',[password]='"&password&"',[p]='"&p&"',[v1]='"&wdId&"' where id="&id
		conn.execute(sql)
		'sql="delete from userInfo where id="&id
		'conn.execute(sql)
		'sql="insert into userInfo ([username],[password],[p]) values ('"&username&"','"&password&"','"&p&"')"
		'conn.execute(sql)
		if err.number=0 then
			response.write "{success:true,msg:3}"
		else
			response.write "{success:false,msg:4}"
		end if
	else
		if username = "admin" then
			response.write "{success:true,msg:1}"
		else
			sqlstr = "select count(*) as cc from userInfo where username='"&username&"'"
			rs.open sqlstr,conn,1,1
			if rs("cc") = 0 then
				sql="insert into userInfo ([username],[password],[p],[v1]) values ('"&username&"','"&password&"','"&p&"','"&wdId&"')"
				conn.execute(sql)
				if err.number=0 then
					response.write "{success:true,msg:0}"
				else
					response.write "{success:true,msg:1}"
				end if
			else
					response.write "{success:true,msg:1}"
			end if
		end if
	end if
elseif sType = "del" then
	arrvalue=split(id,",")
    for i=0 to ubound(arrvalue)
      	on error resume next
	  	sql="delete from userInfo where id=" & arrvalue(i)
		conn.execute(sql)
    next
    
else
end if

conn.close

%>